$(function () {

    initTreeTable();
});

function initTreeTable() {
    var options = {
        code: "menuId",
        parentCode: "parentId",
        uniqueId: "menuId",
        expandAll: false,
        expandFirst: true,
        url: prefix + "/list",
        createUrl: prefix + "/addInit/{id}",
        updateUrl: prefix + "/editInit/{id}",
        removeUrl: prefix + "/remove/{id}",
        modalName: "菜单",
        columns: [{
            field: 'selectItem',
            radio: true
        },{
            title: '菜单名称',
            field: 'menuName',
            width: '20%',
            formatter: function (value, row, index) {
                if($.common.isEmpty(row.menuIcon)){
                    return row.menuName;
                }else{
                    return '<i class="' + row.menuIcon + '"></i> <span class="nav-label">' + row.menuName + '</span>';
                }
            }
        },{
            field: 'menuSort',
            title: '排序',
            width: '10%',
            align: "left"
        },{
            title: '菜单URL',
            field: 'menuUrl',
            width: '15%',
            align: "left"
        },{
            title: '类型',
            field: 'menuType',
            width: '10%',
            align: "left",
            formatter: function(value, item, index) {
                if (item.menuType == '1') {
                    return '<span class="label label-success">目录</span>';
                }
                else if (item.menuType == '2') {
                    return '<span class="label label-primary">菜单</span>';
                }
                else if (item.menuType == '3') {
                    return '<span class="label label-warning">按钮</span>';
                }
            }
        },{
            field: 'isHide',
            title: '可见',
            width: '10%',
            align: "left",
            formatter: function(value, row, index) {
                return $.table.selectDictValue(datas, row.isHide);
            }
        },{
            field: 'permission',
            title: '权限标识',
            width: '15%',
            align: "left",
        },{
            title: '操作',
            width: '20%',
            align: "left",
            formatter: function(value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editFull(\'' + row.menuId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="#" onclick="$.operate.addFull(\'' + row.menuId + '\')"><i class="fa fa-plus"></i>新增</a> ');
                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.menuId + '\')"><i class="fa fa-remove"></i>删除</a>');
                return actions.join('');
            }
        }]
    }
    $.treeTable.init(options);
}


function remove(id) {
    $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function() {
        $.ajax({
            type : 'post',
            url: prefix + "/remove/" + id,
            success : function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(result.msg);
                    $.treeTable.refresh();
                } else {
                    $.modal.msgError(result.msg);
                }
            }
        });
    });
}